package com.shuai.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

import com.shuai.sql.SQL;
import com.shuai.stickynote.R;
import com.shuai.stickynote.TaskNote;

import java.util.ArrayList;

public class TaskRemoteViewFactory implements RemoteViewsService.RemoteViewsFactory {
    private Context context;
    public static ArrayList<TaskNote> tasks = new ArrayList<>();
    private String group = "";
    private String TAG = "fuck";

    public TaskRemoteViewFactory(Context context, Intent intent) {
        this.context = context;
        if (tasks == null) tasks = new ArrayList<>();
//        group = intent.getStringExtra("group");
//        SQL sql = new SQL(context);
//        tasks = sql.selectTaskByGroup(group);
//        Log.d(TAG, "TaskRemoteViewFactory: "+tasks.size());
    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onDataSetChanged() {

    }

    @Override
    public void onDestroy() {
        tasks.clear();
    }

    @Override
    public int getCount() {
        return tasks.size();
    }

    @Override
    public RemoteViews getViewAt(int position) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.adapter_widget_task_list_item);
        if (TextUtils.equals(tasks.get(0).getTagType(),TaskNote.TYPE_SPOT)){
            views.setTextViewText(R.id.adapter_widget_task_type,"●");
//            views.setTextViewTextSize(R.id.adapter_widget_task_type,20,10);
        }else {
            views.setTextViewText(R.id.adapter_widget_task_type,(position+1)+".");
            views.setTextViewTextSize(R.id.adapter_widget_task_type,2,20);
        }
        views.setTextViewText(R.id.adapter_widget_task_content,tasks.get(position).getContent());
        return views;
    }

    @Override
    public RemoteViews getLoadingView() {
        return null;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }
}
